package net.dntuan.training.hibernate.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.GsonBuilder;

public final class TestUtils {

	private static final Logger LOGGER = LoggerFactory.getLogger(TestUtils.class);

	private TestUtils() {
	}

	public static String getJsonString(Object obj) {
		GsonBuilder builder = new GsonBuilder();
		builder.addSerializationExclusionStrategy(new ExclusionStrategy() {

			@Override
			public boolean shouldSkipField(FieldAttributes f) {
				return false;
			}

			@Override
			public boolean shouldSkipClass(Class<?> clazz) {
				if (clazz.getName().contains("org.hibernate.")) {
					LOGGER.debug("skip serializing " + clazz.getName());
					return true;
				}
				return false;
			}
		});
		return builder.create().toJson(obj);
	}
}
